/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.agi.myhome.util;

import java.io.Serializable;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

/**
 *
 * @author Renato
 */

@RequestScoped
@Named(value = "bundleUtil")
public class Bundle implements Serializable{
    private GetMessage getMessage;
    ResourceBundle rb;
        
    public Bundle(){
        try{
            rb=ResourceBundle.getBundle("br.com.agi.myhome.resource.messages");
            getMessage=new Bundle_Perfeito();            
        }catch(MissingResourceException e){
            getMessage=new Bundle_Defeito();
        }
    }
    public String getString(String bundle){
        return getMessage.getMessage(bundle);
    }
    
    private interface GetMessage{
        public String getMessage(String bundle);
    }
    
    private class Bundle_Perfeito implements GetMessage{
        @Override
        public String getMessage(String bundle) {
            return rb.getString(bundle);
        }        
    }
    
    private class Bundle_Defeito implements GetMessage{
        @Override
        public String getMessage(String bundle) {
            return "Impossível ler bundle [" + bundle + "]";
        }        
    }
}
